#include "LLogicSkill.h"
#include "GLGlobalProtocol.h"

CLLogicSkill::CLLogicSkill(void)
{
}


CLLogicSkill::~CLLogicSkill(void)
{
}

void CLLogicSkill::LogicInit() {
	//	AddLogicType(DCLTUserInfo);
}

bool CLLogicSkill::CatchLogic(const ProtocolBase *head, char * data, uint32_t len, void * connect) {
	LSocket* tConnect = (LSocket*)(connect);
	switch (head->m_Logic) {
	case GLSLTPersonBattleSkill:
		if (head->m_From == GLPFromServer) {
			switch (head->m_Action) {
			case GLPAUpgrade:
				onPersonBattleUpgrade(head, data, len);
				break;
			case GLPAUp:
				onPersonBattleUp(head, data, len);
				break;
			case GLPADown:
				onPersonBattleDown(head, data, len);
				break;
			case GLPASet:
				onPersonBattleInit(head, data, len);
				break;
			default:
				return false;
				break;
			}
		}
		break;
	case GLSLTPersonLifeSkill:
		if (head->m_From == GLPFromServer) {
			switch (head->m_Action) {
			case GLPAUpgrade:
				onPersonLifeUpgrade(head, data, len);
				break;
			case GLPASet:
				onPersonLifeInit(head, data, len);
				break;
			default:
				return false;
				break;
			}
		}
		break;
	case GLSLTBodyBattleSkill:
		if (head->m_From == GLPFromServer) {
			switch (head->m_Action) {
			case GLPAUpgrade:
				onBodyBattleUpgrade(head, data, len);
				break;
			case GLPAUp:
				onBodyBattleUp(head, data, len);
				break;
			case GLPADown:
				onBodyBattleDown(head, data, len);
				break;
			case GLPASet:
				onBodyBattleInit(head, data, len);
				break;
			default:
				return false;
				break;
			}
		}
		break;
	default:
		return false;
		break;
	}
	return true;
}
/*
void CLLogicSkill::Create() {
	CreateGroupReq	tCreate;
	tCreate.m_UserId = m_Oneself->GetBaseInfo().m_Uid;

	m_LogicConnect->SendLenAndData((const char*)&tCreate, sizeof(tCreate));
}
*/

int32_t CLLogicSkill::InitPersonBSkill(int32_t model) {
	int32_t tLimit = m_LogicConfig->GetBUpLevelLimit(model);
	if (m_Oneself->GetProperty().AllProp[BPTLev] < tLimit)
		return CommonErrnoLevelLow;

	int32_t tSkillType = m_Oneself->GetSkill().m_BattleSkill.AllSkill[model].m_Type;
	if (tSkillType != EntityTypeNone)
		return GLSkillErrnoHasSkill;

	m_InitSkill.m_UserId = m_Oneself->GetBaseInfo().m_Uid;
	m_InitSkill.m_Logic = GLSLTPersonBattleSkill;
	m_InitSkill.m_SkillModel = model;

	m_LogicConnect->SendLenAndData((const char*)&m_InitSkill, sizeof(m_InitSkill));
	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::UpPersonBSkill(int32_t model, const ContainerOperateGoodsInfo& pos) {
	m_UpSkill.m_UserId = m_Oneself->GetBaseInfo().m_Uid;
	m_UpSkill.m_Logic = GLSLTPersonBattleSkill;
	m_UpSkill.m_SkillModel = model;
	m_UpSkill.m_SkillPos = pos;

	m_LogicConnect->SendLenAndData((const char*)&m_UpSkill, sizeof(m_UpSkill));
	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::DownPersonBSkill(int32_t model) {
	m_DownSkill.m_UserId = m_Oneself->GetBaseInfo().m_Uid;
	m_DownSkill.m_Logic = GLSLTPersonBattleSkill;
	m_DownSkill.m_SkillModel = model;
	m_DownSkill.m_Condition;
	m_LogicConnect->SendLenAndData((const char*)&m_DownSkill, sizeof(m_DownSkill));
	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::UpgradePersonBSkill(int32_t model) {
	int32_t tSkillType = m_Oneself->GetSkill().m_BattleSkill.AllSkill[model].m_Type;
	int32_t tSkillLevel = m_Oneself->GetSkill().m_BattleSkill.AllSkill[model].m_Level;
	BaseProperty& tProp = m_Oneself->GetProperty();

	if (tSkillType == EntityTypeNone)
		return GLSkillErrnoNoneSkill;

	if (tProp.AllProp[BPTLev] <= tSkillLevel)
		return CommonErrnoLevelLow;

	const PropertyCondition* tNeed = m_LogicConfig->GetAUpgradePropNeed(tSkillLevel + 1);
	for (uint8_t i = 0; i != tNeed->m_Count; ++i) {
		const PropertyInfo& tNeedProp = tNeed->m_Property[i];
		if (tProp.AllProp[tNeedProp.m_Type] < tNeedProp.m_Value)
			return CommonErrnoPropertyLow;
	}

	m_StudySkill.m_UserId = m_Oneself->GetBaseInfo().m_Uid;
	m_StudySkill.m_Logic = GLSLTPersonBattleSkill;
	m_StudySkill.m_SkillModel = model;
	m_StudySkill.m_SkillLevel = m_Oneself->GetSkill().m_BattleSkill.AllSkill[model].m_Level;
	m_StudySkill.m_Number = 1;
	m_StudySkill.m_Condition = *tNeed;

	m_LogicConnect->SendLenAndData((const char*)&m_StudySkill, sizeof(m_StudySkill));
	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::InitPersonLSkill(int32_t model) {

	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::UpgradePersonLSkill(int32_t model) {

	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::InitBodyBSkill(int32_t model) {

	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::UpBodyBSkill(int32_t model) {

	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::DownBodyBSkill(int32_t model) {

	return CommonErrnoSucceed;
}

int32_t CLLogicSkill::UpgradeBodyBSkill(int32_t model) {

	return CommonErrnoSucceed;
}

void CLLogicSkill::onPersonBattleInit(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onPersonBattleUp(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onPersonBattleDown(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onPersonBattleUpgrade(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onPersonLifeInit(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onPersonLifeUpgrade(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onBodyBattleInit(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onBodyBattleUp(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onBodyBattleDown(const ProtocolBase *head, char * data, uint32_t len) {

}

void CLLogicSkill::onBodyBattleUpgrade(const ProtocolBase *head, char * data, uint32_t len) {

}
